package com.tangmu.rabbits.adapter.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tangmu.rabbits.R;

import java.util.List;

/**
 * Created by Administrator on 2018/5/2.
 */

public class LvAdapter extends BaseAdapter {

    private Context mContext;
    private List<String> datas;
    private LayoutInflater inflater;

    public LvAdapter(Context mContext, List<String> datas) {
        this.mContext = mContext;
        this.datas = datas;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LViewHolder vh = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_home_lsit, parent, false);
            vh = new LViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (LViewHolder) convertView.getTag();
        }

        vh.tvItem.setText("" + datas.get(position));
        return convertView;
    }

    class LViewHolder {

        TextView tvItem;

        public LViewHolder(View itemView) {
            tvItem = itemView.findViewById(R.id.tv_home_goods_name);
        }
    }
}
